<template>
  <a-modal
    title='告警详情'
    :width='740'
    :visible='visible'
    :confirmLoading='loading'
    @cancel="() => { $emit('cancel') }"
    :footer='null'
  >
    <div style='max-height: 500px;overflow: auto'>
      <a-spin :spinning='loading'>

        <a-form :form='form' v-bind='formLayout'>
          <a-form-item label='发生时间'>
            <a-input disabled placeholder='请输入运维名称'
                     v-decorator="['genTime']" />
          </a-form-item>
          <a-form-item label='确认时间'>
            <a-input disabled placeholder='请输入确认时间'
                     v-decorator="['confirmTime']" />
          </a-form-item>
          <a-form-item label='告警信息'>
            <a-input disabled placeholder='请输入告警信息' v-decorator="['alarmValue']" />
          </a-form-item>
          <a-form-item label='点位名称'>
            <a-input disabled placeholder='请输入点位名称' v-decorator="['positionName']" />
          </a-form-item>
          <a-form-item label='告警类型'>
            <a-input disabled placeholder='请输入安装位置' v-decorator="['alarmType']" />
          </a-form-item>
          <a-form-item label='告警级别'>
            <a-input disabled placeholder='请输入告警级别' v-decorator="['alarmLevel']" />
          </a-form-item>
          <a-form-item label='确认人' v-show='model && model.confirmBy'>
            <a-input disabled placeholder='' v-decorator="['confirmBy']" />
          </a-form-item>
          <a-form-item label='确认信息'  v-show='model && model.confirmMsg'>
            <a-input disabled type='textarea' placeholder='' v-decorator="['confirmMsg']" />
          </a-form-item>
        </a-form>
      </a-spin>
    </div>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import { strPattern1 as userNamePattern, phonePattern } from '@/reges'
import { findDataDicInfoByType } from '@/api/dataDicInfo'
import TagSelectOption from '@/components/TagSelect/TagSelectOption'
// 表单字段
const fields = ['alarmLevel', 'alarmType', 'positionName', 'alarmValue', 'confirmTime', 'genTime', 'confirmBy', 'confirmMsg']

export default {
  components: { TagSelectOption },
  props: {
    visible: {
      type: Boolean,
      required: true
    },

    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  data() {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 21 }
      }
    }
    return {
      form: this.$form.createForm(this),
      queryParam: {},
      phonePattern,
      roleList: [],
      systemId: ''
    }
  },
  created() {
    // 防止表单未注册
    fields.forEach(v => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
    this.getdictionaries()
  },
  methods: {
    getdictionaries() {
      findDataDicInfoByType(2).then(res => {
        this.roleList = res
      })
    },
    validatorPhone(rule, value, callback) {
      if (!value) {
        callback(new Error('请输入设备名称'))
      } else {
        if (!/^\S*$/.test(value)) {
          callback(new Error('请勿输入空格等特殊字符!'))
        } else {
          callback()
        }
      }
    },
    validaNumber(rule, value, callback) {
      if (!value) {
        callback(new Error('请输入设备编号'))
      } else {
        if (!/^[A-Za-z0-9]+$/.test(value)) {
          callback(new Error('请输入字母加数字组合!'))
        } else {
          callback()
        }
      }
    }
  }
}
</script>
<style lang='less' scoped>
.ant-modal-body {
  height: 700px;
  overflow: auto;
}
</style>
